<template>
    <div class="search-div">
        <!-- 搜索表单 -->
        <el-form label-width="70px" size="small">
            <el-form-item label="角色名称">
                <el-input style="width: 100%" placeholder="角色名称"></el-input>
            </el-form-item>
            <el-row style="display:flex">
                <el-button type="primary" @click="fetchData" size="small">
                    搜索
                </el-button>
                <el-button size="small">重置</el-button>
            </el-row>
        </el-form>

        <!-- 添加按钮 -->
        <div class="tools-div">
            <el-button type="success" size="small" @click="addModelRef.show(null)">添 加</el-button>
        </div>


        <el-table :data="list" style="width: 100%; margin-bottom: 20px" row-key="id" border default-expand-all>
            <el-table-column prop="title" label="菜单标题" />
            <el-table-column prop="component" label="路由名称" />
            <el-table-column prop="sortValue" label="排序" />
            <el-table-column prop="status" label="状态" #default="scope">
                {{ scope.row.status == 1 ? '正常' : '停用' }}
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" />

            <el-table-column label="操作" align="center" width="280" #default="scope">
                <el-button type="success" size="small" @click="childModelRef.show(scope.row.id)">
                    添加下级节点
                </el-button>
                <el-button type="primary" size="small" @click="editModelRef.show(scope.row)">
                    修改
                </el-button>
                <el-button type="danger" size="small" @click="remove(scope.row.id)">
                    删除
                </el-button>
            </el-table-column>
        </el-table>

     
    </div>
    <add-model ref="addModelRef" @refresh="fetchData" />
    <edit-model ref="editModelRef" @refresh="fetchData" />
    <child-model ref="childModelRef" @refresh="fetchData" />
</template>

<script setup>
import { ref } from 'vue';
import addModel from './components/add-model.vue';
import editModel from './components/edit-model.vue';
import { getAllMenus,removeSysMenuById } from '@/api/menu';
import childModel from './components/child-model.vue';
const addModelRef = ref()
const queryDto = ref()
const editModelRef = ref()
const childModelRef = ref()
// 分页条总记录数
let total = ref(0)
const pageParams = ref({
    pageNum: 1,
    pageSize: 10
})
// 定义表格数据模型
let list = ref([
    { "id": 9, "roleName": "系统管理员", "roleCode": "xtgly", "createTime": '2023-07-31' },
    { "id": 10, "roleName": "商品管理员", "roleCode": "spgly", "createTime": '2023-07-31' }
])

// 搜索按钮点击事件处理函数
const searchSysRole = () => {
    //queryDto.value.roleName = ""
    fetchData();
}
// 远程调用后端分页查询接口
const fetchData = async () => {

    const { data, } = await getAllMenus();
    list.value = data;

}

const handleDelete = (id) => {
    ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
        // 确定
        deleteRole(id).then(() => {
            ElMessage({
                type: 'success',
                message: '删除成功!'
            })
            fetchData()
        })
    })
}

const remove = (id) => {
    removeSysMenuById(id).then(() => {
        ElMessage({
            type: 'success',
            message: '删除成功!'
        })
        fetchData()
    })

}

fetchData()

</script>

<style scoped>
.search-div {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #ebeef5;
    border-radius: 3px;
    background-color: #fff;
}

.tools-div {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid #ebeef5;
    border-radius: 3px;
    background-color: #fff;
}
</style>